import axios from "axios";
let config = {
    xsrfCookieName: 'csrfToken',
    xsrfHeaderName: 'x-csrf-token',
    // baseURL: process.env.baseURL || process.env.apiUrl || ""
    // timeout: 60 * 1000, // Timeout
    // withCredentials: true, // Check cross-site Access-Control
};

const _axios = axios.create(config);

export function api(url, data) {
    return new Promise((res, rej) => {
        _axios.post(url, data).then(({ data }) => {
            if (data.error) {
                rej(data.meg)
            } else {
                res(data.data)
            }
        }).catch(() => {
            rej('服务器出错')
        })
    }) 
}


